package com.zzx.controller;

import com.zzx.service.ChatHistoryService;

import com.zzx.config.CommonConfiguration;
import com.zzx.vo.MessageVO;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.messages.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ai/history")
public class ChatHistoryController {
    @Autowired
    private ChatHistoryService chatHistoryService;
    @Autowired
    private ChatMemory chatMemory;

    @GetMapping("/{type}")
    public List<String> getHistory(@PathVariable String type) {
        List<String> chatIds = chatHistoryService.getChatIds(type, null);
        return chatIds;
    }

    @GetMapping("/{type}/{chatId}")
    public List<MessageVO> getMessage(@PathVariable String type, @PathVariable String chatId) {
        List<Message> messages = chatMemory.get(chatId);
        return messages.stream().map(message -> {
            return new MessageVO(message);
        }).toList();
    }


}
